package com.gitee.magic.converter;

import java.math.BigDecimal;

import com.gitee.magic.core.converter.AbstractConverterEditor;

/**
 * @author start
 */
public class BigDecimalConverterEditor extends AbstractConverterEditor<String>  {
	
	public BigDecimalConverterEditor(Class<?> prototype) {
		super(prototype);
	}

	@Override
	public void restore(Object value) {
		if(value!=null) {
			setValue(new BigDecimal(String.valueOf(value)).stripTrailingZeros());
		}
	}

	@Override
	public String converter() {
		if(getValue()==null) {
			return null;
		}
		BigDecimal val=(BigDecimal)getValue();
		return val.stripTrailingZeros().toPlainString();
	}

	@Override
	public Object getSource() {
		return converter();
	}
	
}
